﻿<!DOCTYPE html>
<html>
<head>
<%
    include("/static/include/title.html"){}
    include("/static/include/css.html"){}
    include("/static/include/js.html"){}
%>
</head>
<body>
<div class="layui-fluid">
	<form id="fUpdate" class="layui-form" action="#" onsubmit="return false" method="post">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-header">修改密码</div>
				<div class="layui-card-body" pad15>

					<div class="layui-form" lay-filter="">
						<div class="layui-form-item">
							<label class="layui-form-label">当前密码</label>
							<div class="layui-input-inline">
								<input type="password" name="oldPassword" autocomplete="off" class="layui-input" maxlength="20">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">新密码</label>
							<div class="layui-input-inline">
								<input type="password" name="password" autocomplete="off" id="LAY_password" class="layui-input" maxlength="20">
							</div>
							<div class="layui-form-mid layui-word-aux">6位以上，必须包含字母和数字</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">确认新密码</label>
							<div class="layui-input-inline">
								<input type="password" name="password2" autocomplete="off" class="layui-input" maxlength="20">
							</div>
						</div>
						<div class="layui-form-item">
							<span style="color:#FF5722;weight:bold;padding-left:28px;">注意：</span>密码修改成功后，将退出并要求用新密码重新登录！
						</div>
						
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" onclick="doUpdatePassword();">确认修改</button>
							</div>
						</div>
					</div>

				</div>
			</div>
		</div>
	</div>
	</form>
</div>
<script>
	layui.use(['form'], function(){
        var form  = layui.form;
        // 渲染表单radio、select、checkbox
        form.render();
    });

    function validate(theForm) {
        var p = theForm["password"].value;

        if(p == "") {
            $.message("请输入新密码！");
            theForm["password"].focus();
            return false;
        }

        if(p.length < 6) {
        	$.message("密码必须在6位以上！");
        	theForm["password"].focus();
            return false;
        }

        var myreg = /[a-zA-Z]+/;
        if(!myreg.test(p)) {
            $.message("密码必须包含字符！");
            theForm["password"].focus();
            return false;
        }
        var myreg = /\d+/;
        if(!myreg.test(p)) {
            $.message("密码必须包含数字！");
            theForm["password"].focus();
            return false;
        }

        if(theForm["password"].value != theForm["password2"].value) {
            $.message("新密码和验证密码不一致！");
            theForm["password"].focus();
            return false;
        }

        return true;
    }

    function doUpdatePassword() {
		var theForm = document.forms[0];
		if(!validate(theForm)) {
		    return;
		}

		// 提交
        $.ajax({
            url: "passwordUpdate.do"
            ,type: "post"
            ,data: $("#fUpdate").serializeJSON()
            ,dataType:'json'
            ,traditional: true
            ,success:function(result) {
            	var bl = (result != null && result.statusCode == 200);
            	if(bl) {
            		result.message = "密码修改成功，请牢记新密码！<br/><br/>请点击“确定”按钮退出并使用新密码登录！";
            	}
            	
                $.alert(result.message, function(){
                    if(bl) {
                    	// 退出重新登录
                    	top.location.replace("../system/logout.do");
                    }
                });
            }
        })
	}
</script>
</body>
</html>